package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.come.Frame.ZhuFrame;
import org.come.bean.JadeorGoodstableBean;
import org.come.entity.Goodstable;
import org.come.mouslisten.TransferEquiMouslisten;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.Util;

import com.tool.btn.SwitchPageBtn;
import com.tool.btn.WorkshopBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



/**
 * @author Administrator 拆解/转移
 */
public class TransferJpanel extends JPanel {

    private static WorkshopBtn workshopBtn;// 转移/拆解按钮
    private static BigDecimal money,// 消耗金钱
            value;// 消耗灵修值
    private static JLabel labtz,// 套装
            labzb;// 未合成玉符装备

    private SwitchPageBtn leftpageBtn1,// 上一页按钮(套装)
            rightpageBtn1,// 下一页按钮(套装)
            leftpageBtn2,// 上一页按钮
            rightpageBtn2;// 下一页按钮

    public static JLabel[] EquipListJlabel = new JLabel[9];// 放置9个套装
    public static TransferEquiMouslisten[] equiMouslistens = new TransferEquiMouslisten[9];
    public static JLabel[] EquipListJlabel2 = new JLabel[9];// 放置9个未合成玉符装备
    public static TransferEquiMouslisten[] equiMouslistens2 = new TransferEquiMouslisten[9];

    private static JadeorGoodstableBean goodstableBean = new JadeorGoodstableBean();
    private static Goodstable goodstable;// 装备

    public static int page = 0;// 当前显示第几页套装
    public static int page2 = 0;// 当前显示第几页装备

    public TransferJpanel() {
        if ("水墨UI".equals(MyIsif.getStyle())) {
            this.setPreferredSize(new Dimension(490, 428));
            this.setLayout(null);
            this.setOpaque(false);

            // 上一页按钮
            leftpageBtn1 = new SwitchPageBtn("skin/8100226/button/10.png", 1, 7);
            leftpageBtn1.setBounds(120, 190, 18, 18);
            this.add(leftpageBtn1);

            // 下一页按钮
            rightpageBtn1 = new SwitchPageBtn("skin/8100226/button/9.png", 1, 8);
            rightpageBtn1.setBounds(145, 190, 18, 18);
            this.add(rightpageBtn1);

            // 上一页按钮
            leftpageBtn2 = new SwitchPageBtn("skin/8100226/button/10.png", 1, 9);
            leftpageBtn2.setBounds(120, 400, 18, 18);
            this.add(leftpageBtn2);

            // 下一页按钮
            rightpageBtn2 = new SwitchPageBtn("skin/8100226/button/9.png", 1, 10);
            rightpageBtn2.setBounds(145, 400, 18, 18);
            this.add(rightpageBtn2);

            // 放置9个套装
            for (int i = 0; i < 9; i++) {
                EquipListJlabel[i] = new JLabel();
                int row = i % 3;
                int col = i / 3;
                EquipListJlabel[i].setBounds(15 + row * 51, 38 + col * 51, 49, 49);
                equiMouslistens[i] = new TransferEquiMouslisten(i, this, 2);
                EquipListJlabel[i].addMouseListener(equiMouslistens[i]);
                this.add(EquipListJlabel[i]);

                EquipListJlabel2[i] = new JLabel();
                int row2 = i % 3;
                int col2 = i / 3;
                EquipListJlabel2[i].setBounds(15 + row2 * 51, 247 + col2 * 51, 49, 49);
                equiMouslistens2[i] = new TransferEquiMouslisten(i, this, 1);
                EquipListJlabel2[i].addMouseListener(equiMouslistens2[i]);
                this.add(EquipListJlabel2[i]);
            }

            // 套装
            labtz = new JLabel();
            labtz.setBounds(241, 124, 54, 51);
            labtz.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = goodstableBean.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labtz);
            // 未合成玉符装备
            labzb = new JLabel();
            labzb.setBounds(356, 124, 54, 51);
            labzb.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = TransferJpanel.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labzb);

            // 转移/拆解按钮
            workshopBtn = new WorkshopBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "拆解", 6);
            workshopBtn.setBounds(288, 352, 59, 24);
            this.add(workshopBtn);
        } else {
            this.setPreferredSize(new Dimension(490, 428));
            this.setLayout(null);
            this.setOpaque(false);

            // 上一页按钮
            leftpageBtn1 = new SwitchPageBtn("inkImg/hongmu/2/30_png.button.btn_8.png", 1, 7);
            leftpageBtn1.setBounds(120, 190, 18, 18);
            this.add(leftpageBtn1);

            // 下一页按钮
            rightpageBtn1 = new SwitchPageBtn("inkImg/hongmu/2/36_png.button.btn_7.png", 1, 8);
            rightpageBtn1.setBounds(145, 190, 18, 18);
            this.add(rightpageBtn1);

            // 上一页按钮
            leftpageBtn2 = new SwitchPageBtn("inkImg/hongmu/2/30_png.button.btn_8.png", 1, 9);
            leftpageBtn2.setBounds(120, 400, 18, 18);
            this.add(leftpageBtn2);

            // 下一页按钮
            rightpageBtn2 = new SwitchPageBtn("inkImg/hongmu/2/36_png.button.btn_7.png", 1, 10);
            rightpageBtn2.setBounds(145, 400, 18, 18);
            this.add(rightpageBtn2);

            // 放置9个套装
            for (int i = 0; i < 9; i++) {
                EquipListJlabel[i] = new JLabel();
                int row = i % 3;
                int col = i / 3;
                EquipListJlabel[i].setBounds(15 + row * 51, 38 + col * 51, 49, 49);
                equiMouslistens[i] = new TransferEquiMouslisten(i, this, 2);
                EquipListJlabel[i].addMouseListener(equiMouslistens[i]);
                this.add(EquipListJlabel[i]);

                EquipListJlabel2[i] = new JLabel();
                int row2 = i % 3;
                int col2 = i / 3;
                EquipListJlabel2[i].setBounds(15 + row2 * 51, 247 + col2 * 51, 49, 49);
                equiMouslistens2[i] = new TransferEquiMouslisten(i, this, 1);
                EquipListJlabel2[i].addMouseListener(equiMouslistens2[i]);
                this.add(EquipListJlabel2[i]);
            }

            // 套装
            labtz = new JLabel();
            labtz.setBounds(241, 124, 54, 51);
            labtz.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = goodstableBean.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labtz);
            // 未合成玉符装备
            labzb = new JLabel();
            labzb.setBounds(356, 124, 54, 51);
            labzb.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = TransferJpanel.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labzb);

            // 转移/拆解按钮
            workshopBtn = new WorkshopBtn("inkImg/hongmu/1/w50.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "拆 解", 6);
            workshopBtn.setBounds(288, 352, 60, 26);
            this.add(workshopBtn);
        }

    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if ("水墨UI".equals(MyIsif.getStyle())) {
            if (icon == null) {
                icon = new ImageIcon("inkImg/newbackground/B246.png");
            }
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 490, 428, this);
            // 画拥有金钱
            Util.drawMoney(g, 317, 274);
            // 画消耗金钱
            if (money != null) {
                Util.drawPrice(g, money, 317, 248);
            }
            // 画套装信息
            GoodsListFromServerUntil.drawRoleSuit(g, 15, 38, page, 9);
            // 画装备信息
            GoodsListFromServerUntil.drawIdlEqu(g, 15, 247, page2, 9, 3);
            g.setColor(Color.white);
            // 画拥有的灵修值
            if (RoleData.getRoleData().getLoginResult().getScoretype("灵修值") != null) {
                g.drawString(RoleData.getRoleData().getLoginResult().getScoretype("灵修值") + "", 317, 326);
            }
            // 画所需灵修值
            if (value != null) {
                g.drawString(value + "", 317, 300);
            }
        } else {
            if (icon == null) {
                icon = new ImageIcon("inkImg/hongmu/2/setsynthesis_cczy.png");
            }
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 490, 428, this);
            // 画拥有金钱
            Util.drawMoney(g, 317, 274);
            // 画消耗金钱
            if (money != null) {
                Util.drawPrice(g, money, 317, 248);
            }
            // 画套装信息
            GoodsListFromServerUntil.drawRoleSuit(g, 15, 38, page, 9);
            // 画装备信息
            GoodsListFromServerUntil.drawIdlEqu(g, 15, 247, page2, 9, 3);
            g.setColor(Color.white);
            // 画拥有的灵修值
            if (RoleData.getRoleData().getLoginResult().getScoretype("灵修值") != null) {
                g.drawString(RoleData.getRoleData().getLoginResult().getScoretype("灵修值") + "", 317, 326);
            }
            // 画所需灵修值
            if (value != null) {
                g.drawString(value + "", 317, 300);
            }
        }
    }

    /**
     * 清空界面
     */
    public static void clearInterface() {
        money = null;
        value = null;
        goodstableBean.setGoodstable(null);
        goodstable = null;
        goodstableBean.setType(0);
        labtz.setIcon(null);
        labzb.setIcon(null);
        workshopBtn.setText("拆 解");
    }

    public static BigDecimal getMoney() {
        return money;
    }

    public static void setMoney(BigDecimal money) {
        TransferJpanel.money = money;
    }

    public static BigDecimal getValue() {
        return value;
    }

    public static void setValue(BigDecimal value) {
        TransferJpanel.value = value;
    }

    public static JLabel getLabtz() {
        return labtz;
    }

    public static void setLabtz(JLabel labtz) {
        TransferJpanel.labtz = labtz;
    }

    public static JLabel getLabzb() {
        return labzb;
    }

    public static void setLabzb(JLabel labzb) {
        TransferJpanel.labzb = labzb;
    }

    public static JLabel[] getEquipListJlabel() {
        return EquipListJlabel;
    }

    public static void setEquipListJlabel(JLabel[] equipListJlabel) {
        EquipListJlabel = equipListJlabel;
    }

    public static JLabel[] getEquipListJlabel2() {
        return EquipListJlabel2;
    }

    public static void setEquipListJlabel2(JLabel[] equipListJlabel2) {
        EquipListJlabel2 = equipListJlabel2;
    }

    public static JadeorGoodstableBean getGoodstableBean() {
        return goodstableBean;
    }

    public static void setGoodstableBean(JadeorGoodstableBean goodstableBean) {
        TransferJpanel.goodstableBean = goodstableBean;
    }

    public static Goodstable getGoodstable() {
        return goodstable;
    }

    public static void setGoodstable(Goodstable goodstable) {
        TransferJpanel.goodstable = goodstable;
    }

    public static WorkshopBtn getWorkshopBtn() {
        return workshopBtn;
    }

    public static void setWorkshopBtn(WorkshopBtn workshopBtn) {
        TransferJpanel.workshopBtn = workshopBtn;
    }
}
